iT邦幫忙

2024 iThome 鐵人賽

DAY 1
1
DevOps

時間序列資料庫探討 - Prometheus系列 第 1

Prometheus - 系列文計畫和測試環境架設

  • 分享至 

  • xImage
  •  

系列文計畫

聲明

這是介紹 Prometheus 的鐵人賽系列文。
但我不是資料庫大師,也不是 DevOps 大師。內容都是現學現賣。
如有疏漏錯誤不詳之處,還請各位賢達多多留言指教<(_ _)>,我會盡力補正。

形式

本系列文預計會有十幾個小題,每個小題會以問答的方式呈現。
首先會有一篇敘述文章,仔細說明我們想知道什麼、解決什麼問題。
接著會有一到兩篇對應的文章,作為解答和舉例。

內容規劃

目前計劃如下

  • Prometheus 是什麼
    • Prometheus 在 DevOp 中的角色。
    • 時間序列資料庫的獨特之處。
    • Prometheus 執行環境的模組。
  • Prometheus 怎麼使用
    • 資料結構
    • 資料寫入的方式
    • 資料讀取和分析的方式
    • 常用的結構和表達式舉例
  • Prometheus 執行環境
    • 資料儲存結構
    • 資料寫入的流程
    • 資料讀取的流程
    • 一些奇怪的小問題

測試環境架設

雖然第 0 天還沒介紹 prometheus 是什麼,但為了水一下內容,就先來說明之後實驗用的 prometheus 環境如何架設。
架構大致如圖。
https://ithelp.ithome.com.tw/upload/images/20240915/20154259F3t22lBgW1.png

架設步驟

架設 Prometheus

打開教學 https://prometheus.io/docs/prometheus/latest/getting_started/

架設 Prometheus Pushgateway

scrape_configs:
  - job_name: "push_gateway"
    static_configs:
      - targets: ["localhost:9091"]
  • 對還在跑的 promethues 按 Ctrl+C,再重新執行一次。
  • 用瀏覧器打開 http://localhost:9090/ 找到 Explore metrics,點進去查 pushgateway_build_info,可以看到 promethues 有成功從 pushgateway 拉到東西。
    https://ithelp.ithome.com.tw/upload/images/20240915/20154259zpKS2HbnRg.png

使用 python prometheus client

架好 pushgateway 後,就可以直接用 curl 推資料localhost:9091,等 prometheus 從 localhost:9091/metrics 拉進資料庫。
但手寫 curl 還是不太方便,我們可以用比較友善的python 套件

  • 下載 python 套件 sudo apt install python3-prometheus-client
  • 照抄並執行文件範例程式,就可以在 http://localhost:9090/ 看到結果了。
    https://ithelp.ithome.com.tw/upload/images/20240915/20154259xKl7MC6EVr.png

編譯 Prometheus

為了研究方便,我無可避免會想在 prometheus 執行時插入我的程式碼。
所以自行編譯一次。各位讀者應該沒必要嘗試。

  • git clone https://github.com/prometheus/prometheus.git (確認為最新版本)
  • make 過程會裝新版的 golang, npm
  • 如果跳出 go test 失敗可以先不理它。有出現 prometheus 執行檔就行。
  • 執行 ./prometheus --config.file=prometheus.yml 比照確認沒有問題。

下一篇
Prometheus - 監控系統和時序資料庫的定位
系列文
時間序列資料庫探討 - Prometheus13
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言